package cn.itcast.web.shiro;

import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authc.credential.SimpleCredentialsMatcher;
import org.apache.shiro.crypto.hash.Md5Hash;

public class CustomCredentialsMatcher extends SimpleCredentialsMatcher {


   public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info){

       //1.把token转换为usernamePasswordToke
       UsernamePasswordToken usernamePasswordToken = (UsernamePasswordToken) token;


       String email = usernamePasswordToken.getUsername();

       String password = new String(usernamePasswordToken.getPassword());


       Md5Hash md5Hash = new Md5Hash(password, email);

       String slatPassword = md5Hash.toString();

       Object dbPassword = info.getCredentials();

       return dbPassword.equals(slatPassword);

   }


}
